package org.csmzxy.class2333.innerclass;

class Calculator {
    //对操作对象进行加减计算
    public void performCalculation(int num1, int num2, char operation){
        //局部内部类，用于表示计算器
        class OperationCalculator{
            public int add(){
                return num1 + num2;
            }
            public int subtract(){
                return num1 - num2;
            }
        }
        //创建局部内部类的对象
        OperationCalculator calculator = new OperationCalculator();
        if (operation == '+'){
            //在方法内部访问局部内部类的成员
            System.out.println("计算结果：" + calculator.add());
        }else if (operation == '-'){
            System.out.println("计算结果：" + calculator.subtract());
        }else {
            System.out.println("发生错误！");
        }
    }
}
